package com.nondo.rdp.finance.domain.course;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.nondo.rdp.auth.domain.User;
import com.nondo.rdp.core.domain.base.BaseEntity;
import com.nondo.rdp.finance.config.DbConfig;

/**
 * 求知-课程评分
 */
@Entity
@Table(name = DbConfig.DEFAULT_TABLE_PREFIX + "course_rate")
public class CourseRate extends BaseEntity {
	private static final long serialVersionUID = 70471831418405754L;
	private Long id;// 主键
	private Course course;// 课程
	private User rateUser;// 评分人
	private int rate;// 分数
	// 扩展字段
	private Long courseId; // 课程ID

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@OneToOne
	@JoinColumn(name = "cid")
	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}

	@OneToOne
	@JoinColumn(name = "uid")
	public User getRateUser() {
		return rateUser;
	}

	public void setRateUser(User rateUser) {
		this.rateUser = rateUser;
	}

	@Column(columnDefinition = "int default 5", nullable = false)
	public int getRate() {
		return rate;
	}

	public void setRate(int rate) {
		this.rate = rate;
	}

	@JsonIgnore
	@Transient
	public Long getCourseId() {
		return courseId;
	}

	@JsonSetter
	public void setCourseId(Long courseId) {
		this.courseId = courseId;
	}
}
